package com.coolw.dynamic.thread.pool.controller;

import com.coolw.dynamic.thread.pool.domain.dto.ThreadPoolStatDTO;
import com.coolw.dynamic.thread.pool.service.ThreadPoolStatService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 * 线程池监控请求控制层
 *
 * @author coolw
 * @date 2024/5/17 17:44
 */
@Slf4j
@RequestMapping("/monitor")
@Controller
public class MonitorController {

    @Autowired
    private ThreadPoolStatService threadPoolStatService;

    @GetMapping("/index")
    public String index(Model model) {
        ThreadPoolStatDTO statDTO;
        try {
            statDTO = threadPoolStatService.execute();
        } catch (Exception e) {
            log.error("线程池统计执行异常", e);
            statDTO = new ThreadPoolStatDTO("线程池统计执行异常");
        }
        model.addAttribute("statResult", statDTO);
        return "thread_pool_monitor";
    }
}
